//
//  WSJReadPlistTool.m
//  WSJWoundDesVC
//
//  Created by wsj2015 on 16/3/30.
//  Copyright © 2016年 wsj2015. All rights reserved.
//

#import "WSJReadPlistTool.h"
#import "WoundContentModel.h"



@implementation WSJReadPlistTool



+ (NSArray *)getWoundDesPlistContent{
   
//    NSDictionary *dict =[NSDictionary dictionaryWithContentsOfFile:@"WOULD_DES"];
    NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"WOULD_DES" ofType:@"plist"];
    NSDictionary *dict = [[NSDictionary alloc]initWithContentsOfFile:plistPath];
    return dict[@"WOULD_DES"];
    
}
+ (NSArray*)getModelArrayFromPlist{
    
    NSArray *sectionArray =[WSJReadPlistTool getWoundDesPlistContent];
    NSMutableArray *array =[NSMutableArray array];
    for (NSDictionary *dic in sectionArray) {
        WoundDesModel *model =[WoundDesModel new];
        
        model.isfolden = YES;
        model.sectionTitle = dic[@"title"];
        model.desArray =dic[@"contentArray"];
        NSMutableArray *temArr =[NSMutableArray array];
        for (NSDictionary *contentDict in dic[@"contentArray"]) {
            WoundContentModel *contentModel =[WoundContentModel new];
            contentModel.isSelect = NO;
            contentModel.readonly = [contentDict[@"onlyread"] boolValue];
            contentModel.content = contentDict[@"content"];
            if (contentDict[@"inputType"]) {
                contentModel.inputType = contentDict[@"inputType"];
            }
            
            contentModel.enditType= [WSJReadPlistTool containKeySpecicalWord:contentDict[@"content"]];
            [temArr addObject:contentModel];
            
        }
        model.desArray =temArr;
        [array addObject:model];
    }
    return array;
}

+ (NSInteger)containKeySpecicalWord:(NSString *)str
{
    NSArray *resultArr =[str componentsSeparatedByString:kKeySepcicalWord];
    if (resultArr.count ==2) {
        if ([resultArr[0] isEqualToString:@""]) {
            return 1;
        }else if([resultArr[1] isEqualToString:@""]){
            return 2;
        }
    }else if (resultArr.count ==3){
        return 3;
    }
    return  0;
}


@end
